<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <title>欢迎使用 IMOOC Cake 后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="../assets/css/theme.css">
    <link rel="stylesheet" type="text/css" href="../assets/css/admin-forms.css">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
</head>

<body class="admin-validation-page" data-spy="scroll" data-target="#nav-spy" data-offset="200">
<div id="main">
    <header class="navbar navbar-fixed-top navbar-shadow">
        <div class="navbar-branding">
            <a class="navbar-brand" href="../index.html">
                <H3>Love Cake 后台管理系统</H3>
            </a>
            <span id="toggle_sidemenu_l" class="ad ad-lines"></span>
        </div>
    </header>
    <aside id="sidebar_left" class="nano nano-light affix">
        <div class="sidebar-left-content nano-content">
            <header class="sidebar-header">
                <div class="sidebar-widget author-widget">
                    <div class="media">
                        <a class="media-left" href="#">
                            <img src="../images/head.jpg" class="img-responsive">
                        </a>
                        <div class="media-body">
                            <div class="media-author">管理员</div>
                            <div class="media-links">
                                <a href="/user/login">退出</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="sidebar-widget search-widget hidden">
                    <div class="input-group">
                        <span class="input-group-addon">
                        <i class="fa fa-search"></i>
                        </span>
                        <input type="text" id="sidebar-search" class="form-control" placeholder="Search...">
                    </div>
                </div>
            </header>
            <ul class="nav sidebar-menu">
                <li class="sidebar-label pt20">商品管理</li>
                <li class="active">
                    <a href="/cake_list">
                        <span class="glyphicon glyphicon-book"></span>
                        <span class="sidebar-title">商品列表</span>
                    </a>
                </li>
                <li>
                    <a href="/cake_add_second">
                        <span class="glyphicon glyphicon-home"></span>
                        <span class="sidebar-title">商品上架</span>
                    </a>
                </li>
                <li class="sidebar-label pt20">分类管理</li>
                <li class="active">
                    <a href="/catalog_list" oncick="getPageData()">
                        <span class="glyphicon glyphicon-book"></span>
                        <span class="sidebar-title">分类列表</span>
                    </a>
                </li>
                <li>
                    <a href="/catalog_add">
                        <span class="glyphicon glyphicon-home"></span>
                        <span class="sidebar-title">添加分类</span>
                    </a>
                </li>
            </ul>
            <div class="sidebar-toggle-mini">
                <a href="login.jsp">
                    <span class="fa fa-sign-out"></span>
                </a>
            </div>
        </div>
    </aside>
<section id="content_wrapper">
    <section id="content" class="table-layout animated fadeIn">
        <div class="tray tray-center">
            <div class="content-header">
                <h2> 分类管理</h2>
                <p class="lead"></p>
            </div>
            <div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;">
                <div class="panel  heading-border">
                    <div class="panel-menu">
                        <div class="row">
                            <div class="hidden-xs hidden-sm col-md-3">
                                <div class="btn-group">
                               		<!--  删除按钮 -->
                                    <button type="button" class="btn btn-default light" onclick="batchDel()">
                                        <i class="fa fa-trash"></i>
                                    </button>
                                    	<!-- 增加按钮 -->
                                    <button type="button" class="btn btn-default light">
                                        <i class="fa fa-plus" onclick="window.location.href='/catalog_add'"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel-body pn">
                        <table id="message-table" class="table admin-form theme-warning tc-checkbox-1">
                            <thead>
                            <tr class="">
                                <th class="text-center hidden-xs">Select</th>
                                <th class="hidden-xs">名称</th>
                                <th class="hidden-xs">描述</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="catalogList">
                            
                                
                                    
                                        <!-- <tr class="message-unread">
                                            <td class="hidden-xs">
                                                <label class="option block mn">
                                                    <input type="checkbox" name="mobileos" value="FR">
                                                    <span class="checkbox mn"></span>
                                                </label>
                                            </td>
                                            <td style="padding-left: 100px;">活动仪式</td>
                                            <td></td>
                                            <td>
                                                <a href="catalog_list.jsp?id=14202">删除</a>
                                            </td>
                                        </tr> -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</section>


</div>
<style>
    /* demo page styles */
    body { min-height: 2300px; }

    .content-header b,
    .admin-form .panel.heading-border:before,
    .admin-form .panel .heading-border:before {
        transition: all 0.7s ease;
    }
    /* responsive demo styles */
    @media (max-width: 800px) {
        .admin-form .panel-body { padding: 18px 12px; }
    }
</style>

<style>
    .ui-datepicker select.ui-datepicker-month,
    .ui-datepicker select.ui-datepicker-year {
        width: 48%;
        margin-top: 0;
        margin-bottom: 0;

        line-height: 25px;
        text-indent: 3px;

        color: #888;
        border-color: #DDD;
        background-color: #FDFDFD;

        -webkit-appearance: none; /*Optionally disable dropdown arrow*/
    }
</style>

<!-- jQuery -->
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/jquery-ui.min.js"></script>
<!-- Theme Javascript -->
<script src="../assets/js/utility.js"></script>
<script src="../assets/js/demo/demo.js"></script>
<script src="../assets/js/main.js"></script>
<script src="../assets/js/pages.js"></script>
<!-- END: PAGE SCRIPTS -->
</body>
<script type="text/javascript" src="static/js/jquery-3.5.1.js"></script>
<script type="text/javascript">
	/*function getPageData() {
		var nextPage = 1;*/
		/*var obj = {
				"nextPage":nextPage
			}*/
		/*$.ajax({
			async:true,
			url:"/catalogListPageData",
			type:"post",
			data:JSON.stringify({
                "nextPage":nextPage
            }),
			dataType:"json",
			success:function(data) {
				console.log(data.result.data);
				$('#catalogList').empty();
				for(var i = 0;i<data.result.data.length;i++) {
					var id = data.result.data[i].id;
					if(data.result.data[i].levelId == 1) {
						var str = "<tr class='message-unread'>";
						str += "<td class='hidden-xs'>";
						str += "<label class='option block mn'>";
						str += "<input type='checkbox' name='mobileos' value='FR' id='"+ id +"'>";
						str += "<span class='checkbox mn'></span>";
						str += "</label></td>";
						str += "<td>"+data.result.data[i].catalogName+"</td>";
						str += "<td></td>";
						str += "<td><a href='catalog_list.jsp?id=14202' onclick='del(\"" +id+"\")'>删除</a>";
						str += "</td></tr>";
						$('#catalogList').append(str);
					}
					if(data.result.data[i].levelId == 2) {
						var str = "<tr class='message-unread'>";
						str += "<td class='hidden-xs'>";
						str += "<label class='option block mn'>";
						str += "<input type='checkbox' name='mobileos' value='FR' id='"+ id +"'>";
						str += "<span class='checkbox mn'></span>";
						str += "</label></td>";
						str += "<td style='padding-left: 50px;'>"+data.result.data[i].catalogName+"</td>";
						str += "<td></td>";
						str += "<td><a href='catalog_list.jsp?id=14202' onclick='del(\"" +id+"\")'>删除</a>";
						str += "</td></tr>";
						$('#catalogList').append(str);
					}	
					if(data.result.data[i].levelId == 3) {
						var str = "<tr class='message-unread'>";
						str += "<td class='hidden-xs'>";
						str += "<label class='option block mn'>";
						str += "<input type='checkbox' name='mobileos' value='FR' id='"+ id +"'>";
						str += "<span class='checkbox mn'></span>";
						str += "</label></td>";
						str += "<td style='padding-left: 100px;'>"+data.result.data[i].catalogName+"</td>";
						str += "<td></td>";
						str += "<td><a href='catalog_list.jsp?id=14202' onclick='del(\"" +id+"\")'>删除</a>";
						str += "</td></tr>";
						$('#catalogList').append(str);
					}
				}
				
				
			}
			});*/

        $.ajax({
            async : true,
            url : "/getCatalog",
            type : "post",
            data : {},
            dataType : "json",
            success : function(data) {
                var arr = data.result;
                 console.log(arr);
                $("#catalogList").empty();
                for(var i=0; i<arr.length; i++) {
                    var str = "";
                    str += '<tr class="message-unread">';
                    str += '<td class="hidden-xs">';
                    str += '<label class="option block mn">';
                    str += '<input type="checkbox" name="mobileos" value="' + arr[i].id + '">';
                    str += '<span class="checkbox mn"></span>';
                    str += '</label>';
                    str += '</td>';
                    if(arr[i].levelId == "1") {
                        str += '<td>' + arr[i].catalogName + '</td>';
                    } else if(arr[i].levelId == "2") {
                        str += '<td style="padding-left: 50px;">' + arr[i].catalogName + '</td>';
                    } else if(arr[i].levelId == "3") {
                        str += '<td style="padding-left: 100px;">' + arr[i].catalogName + '</td>';
                    }
                    str += '<td></td>';
                    str += '<td><button onclick="del(' + arr[i].id + ')">删除</button></td>'
                    str += '</tr>';
                    $("#catalogList").append(str);
                }
            }
        });


	/*$().ready(function() {
		getPageData();
	})*/
	//单个删除
		function del(id) {
		var obj = {
			"id" : id
		}
		$.ajax({
			//填写配置选项
			async:true,//默认开启异步
			url:"/catalogDelete",//请求地址
			type:"post",//请求类型
			data:JSON.stringify(obj),//请求参数
            contentType : "application/json;charset=utf-8",
			dataType:"text",//响应数据格式
			success:function(data) {//成功时执行函数，参数为服务器返回的数据
                alert("删除成功");
				window.location.reload();
			}
		});	
	}
	
	//批量删除
	function batchDel() {
		var checkedValues = new Array();
		 $("input[name='mobileos']").each(function() {
             if ($(this).is(':checked')) {
                 checkedValues.push($(this).attr("value"));
             }
         });
		
		 console.log(checkedValues);
		 $.ajax({
				//填写配置选项
				async:true,//默认开启异步
				url:"/catalogBatchDeleyte",//请求地址
				type:"post",//请求类型
				data:JSON.stringify({"ids":checkedValues}),//请求参数
             contentType : "application/json;charset=utf-8",
				dataType:"text",//响应数据格式
				success:function(data) {//成功时执行函数，参数为服务器返回的数据
                    alert("删除成功");
				    window.location.reload();
				}
			});	
	}
</script>
</html>
